package com.sihan.swvp.action.wg;

import java.util.HashMap;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sihan.swvp.action.BaseAction;
import com.sihan.swvp.entity.wg.WgSyjs;
import com.sihan.swvp.service.sys.LogService;
import com.sihan.swvp.service.wg.WgSyjsService;
import com.sihan.swvp.service.wg.WgVideoService;

@Controller
@RequestMapping("/wgSyjsAction")
public class WgSyjsAction extends BaseAction{

	@Autowired
	private WgSyjsService wgSyjsService;
	@Autowired
	private WgVideoService wgVideoService;
	
	@Autowired
	public LogService logService;
	/**
	 * 查询首页警示数据分页
	 * @param zcvName
	 * @param wgvName
	 * @param page
	 * @param limit
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getWgSyjs")
	public Object getWgSyjs(@Param("zcvName")String zcvName,@Param("wgvName")String wgvName,@Param("page")Integer page,@Param("limit")Integer limit){
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("zcvName", zcvName);
		params.put("wgvName", wgvName);
		return pageData(wgSyjsService.getWgSyjs(params, page, limit));
	}
	/**
	 * 查询首页警示数据
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getWgSyjsList")
	public Object getWgSyjsList(){
		return wgSyjsService.getWgSyjs(null, null, null);
	}
	
	@ResponseBody
	@RequestMapping("/addWgSyjs")
	public Object addWgSyjs(WgSyjs bean){
		try {
			
			Long userId=getLoginUser().getId();
			bean.setUpuser(userId);
			Integer nubmer= wgSyjsService.getWgSyjsValidate(bean);
			if(nubmer !=0){
				return failMsg("已存在该标题");
			}
			wgSyjsService.addWgSyjs(bean);
			logService.addUserLog("添加首页警示", "首页警示", getLoginUser().getId(), "添加首页警示："+bean.getTitle(),getRemoteAddr(),1,0);
			return successMsg("");
		} catch (Exception e) {
			e.printStackTrace();
			logService.addUserLog("添加首页警示", "首页警示", getLoginUser().getId(), "添加首页警示："+bean.getTitle(),getRemoteAddr(),0,0);
			return failMsg("服务器异常");
		}
	}
	
	@ResponseBody
	@RequestMapping("/updateWgSyjs")
	public Object updateWgSyjs(WgSyjs bean){
		try {
			bean.setUpuser(getLoginUser().getId());
			Integer nubmer= wgSyjsService.getWgSyjsValidate(bean);
			if(nubmer !=0){
				return failMsg("已存在该标题");
			}
			wgSyjsService.updateWgSyjs(bean);
			logService.addUserLog("修改首页警示", "首页警示", getLoginUser().getId(), "修改首页警示："+bean.getTitle(),getRemoteAddr(),1,0);
			return successMsg("");
		} catch (Exception e) {
			e.printStackTrace();
			logService.addUserLog("修改首页警示", "首页警示", getLoginUser().getId(), "修改首页警示："+bean.getTitle(),getRemoteAddr(),0,0);
			return failMsg("服务器异常");
		}
	}
	
	@ResponseBody
	@RequestMapping("/deleteWgSyjs")
	public Object deleteWgSyjs(@Param("id")Integer id,String title){
		try {
			wgSyjsService.deleteWgSyjs(id);
			logService.addUserLog("删除首页警示", "首页警示", getLoginUser().getId(), "删除首页警示："+title,getRemoteAddr(),1,0);
			return successMsg("");
		} catch (Exception e) {
			e.printStackTrace();
			logService.addUserLog("删除首页警示", "首页警示", getLoginUser().getId(), "删除首页警示："+title,getRemoteAddr(),0,0);
			return failMsg("服务器异常");
		}
	}
	
	/**
	 * 正常视频信息
	 * @param name
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getVideoSynList")
	public Object getVideoSynList(@Param("name")String name,@Param("startTime")String startTime,@Param("endTime")String endTime){
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("name", name);
		params.put("startTime", startTime);
		params.put("endTime", endTime);
		return wgSyjsService.getVideoSynList(params);
	}
	
	/**
	 * 违规视频信息
	 * @param content
	 * @param vname
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getWgVideoList")
	public Object getWgVideoList(@Param("content")String content,@Param("vname")String vname,@Param("videoId")Integer videoId){
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("content", content);
		params.put("vname", vname);
		params.put("videoId", videoId);
		return wgVideoService.getWgVideoList(params, null, null);
	}
	
}
